package com.company.example.controller;

import com.company.example.core.util.DateUtil;
import com.company.example.model.pojo.Activity;
import com.company.example.service.ActivityService;
import com.company.example.task.ActivitySchedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by ywl on 2017/1/22.
 */
@Controller
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @RequestMapping("/index")
    @ResponseBody
    public void index() {
        Activity activity = new Activity();
        activity.setStartTime(DateUtil.parseDateTime("2017-01-23 17:29:00"));
        activity.setEndTime(DateUtil.parseDateTime("2017-01-23 17:30:00"));
        activity.setName("活动11");
        activity.setActivityStatus(0);
        Integer id = activityService.insertActivity(activity);
        System.out.println("活动ID:"+id);
        //查询所有需要定时执行的活动计划
        /*List<Activity> activities = activityService.findUnEndActivities();
        for (Activity activity : activities){
            System.out.println(activity.getName()+"--"+activity.getId());
        }*/
    }

    @RequestMapping("/test")
    @ResponseBody
    public void test() {
        for (Integer id : ActivitySchedule.getActivitiesMap().keySet()) {
            System.out.println("activity-id:"+id);
        }
    }
}
